<!DOCTYPE html>
<html lang="en-US">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>vue3+TS+Element-plus el-pagination分页组件显示中文 | 田超的博客</title>
    <meta name="generator" content="VuePress 1.8.2">
    <link rel="icon" href="logo.png">
    <meta name="description" content="我的技术站">
    
    <link rel="preload" href="/assets/css/0.styles.e4d8b86b.css" as="style"><link rel="preload" href="/assets/js/app.27eb3a33.js" as="script"><link rel="preload" href="/assets/js/2.377be75f.js" as="script"><link rel="preload" href="/assets/js/11.e95a61b2.js" as="script"><link rel="prefetch" href="/assets/js/10.1f869ceb.js"><link rel="prefetch" href="/assets/js/12.18f1abe4.js"><link rel="prefetch" href="/assets/js/3.715098d8.js"><link rel="prefetch" href="/assets/js/4.2a5d96fc.js"><link rel="prefetch" href="/assets/js/5.fd255a4a.js"><link rel="prefetch" href="/assets/js/6.66b67ff0.js"><link rel="prefetch" href="/assets/js/7.9c8176d4.js"><link rel="prefetch" href="/assets/js/8.2dfbea36.js"><link rel="prefetch" href="/assets/js/9.94de72e2.js">
    <link rel="stylesheet" href="/assets/css/0.styles.e4d8b86b.css">
  </head>
  <body>
    <div id="app" data-server-rendered="true"><div class="theme-container"><header class="navbar"><div class="sidebar-button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" role="img" viewBox="0 0 448 512" class="icon"><path fill="currentColor" d="M436 124H12c-6.627 0-12-5.373-12-12V80c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12z"></path></svg></div> <a href="/" class="home-link router-link-active"><!----> <span class="site-name">田超的博客</span></a> <div class="links"><div class="search-box"><input aria-label="Search" autocomplete="off" spellcheck="false" value=""> <!----></div> <nav class="nav-links can-hide"><div class="nav-item"><a href="/" class="nav-link">
  首页
</a></div><div class="nav-item"><a href="http://tianchoy.com" target="_blank" rel="noopener noreferrer" class="nav-link external">
  博客
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></div><div class="nav-item"><a href="https://github.com/tianchoy" target="_blank" rel="noopener noreferrer" class="nav-link external">
  Github
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></div> <!----></nav></div></header> <div class="sidebar-mask"></div> <aside class="sidebar"><nav class="nav-links"><div class="nav-item"><a href="/" class="nav-link">
  首页
</a></div><div class="nav-item"><a href="http://tianchoy.com" target="_blank" rel="noopener noreferrer" class="nav-link external">
  博客
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></div><div class="nav-item"><a href="https://github.com/tianchoy" target="_blank" rel="noopener noreferrer" class="nav-link external">
  Github
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></div> <!----></nav>  <ul class="sidebar-links"><li><section class="sidebar-group collapsable depth-0"><a href="/vue3/" class="sidebar-heading clickable router-link-active open"><span>vue3</span> <span class="arrow down"></span></a> <ul class="sidebar-links sidebar-group-items"><li><a href="/vue3/2021-08-20-1.html" class="sidebar-link">安装vue3</a></li><li><a href="/vue3/2021-08-20-2.html" aria-current="page" class="active sidebar-link">el-pagination分页组件显示中文</a><ul class="sidebar-sub-headers"></ul></li></ul></section></li><li><a href="/ts/" class="sidebar-link">ts</a></li></ul> </aside> <main class="page"> <div class="theme-default-content content__default"><h3 id="vue3-ts-element-plus-el-pagination分页组件显示中文"><a href="#vue3-ts-element-plus-el-pagination分页组件显示中文" class="header-anchor">#</a> vue3+TS+Element-plus el-pagination分页组件显示中文</h3> <div class="custom-block tip"><p class="custom-block-title">1,首先考虑改造一下main.ts</p> <br></div> <div class="language-js extra-class"><pre class="language-js"><code><span class="token comment">// ! element-plus vue3.0</span>
<span class="token keyword">import</span> element <span class="token keyword">from</span> <span class="token string">'element-plus'</span>
<span class="token keyword">import</span> <span class="token string">'element-plus/lib/theme-chalk/index.css'</span>
<span class="token keyword">import</span> locale <span class="token keyword">from</span> <span class="token string">'element-plus/lib/locale/lang/zh-cn'</span> <span class="token comment">//中文</span>
<span class="token comment">//在app中引用</span>
app<span class="token punctuation">.</span><span class="token function">use</span><span class="token punctuation">(</span>ElementPlus<span class="token punctuation">,</span><span class="token punctuation">{</span>locale<span class="token punctuation">}</span><span class="token punctuation">)</span>
</code></pre></div><div class="custom-block tip"><p class="custom-block-title">2,如果得不到解决，那就单独在pagination的组件中解决一下</p> <br></div> <div class="language-js extra-class"><pre class="language-js"><code><span class="token operator">&lt;</span>template<span class="token operator">&gt;</span>
      <span class="token operator">&lt;</span>el<span class="token operator">-</span>config<span class="token operator">-</span>provider <span class="token operator">:</span>locale<span class="token operator">=</span><span class="token string">&quot;locale&quot;</span><span class="token operator">&gt;</span>
      <span class="token operator">&lt;</span>el<span class="token operator">-</span>pagination
        @size<span class="token operator">-</span>change<span class="token operator">=</span><span class="token string">&quot;handleSizeChange&quot;</span>
        @current<span class="token operator">-</span>change<span class="token operator">=</span><span class="token string">&quot;handleCurrentChange&quot;</span>
        <span class="token operator">:</span>current<span class="token operator">-</span>page<span class="token operator">=</span><span class="token string">&quot;currentPage4&quot;</span>
        <span class="token operator">:</span>page<span class="token operator">-</span>sizes<span class="token operator">=</span><span class="token string">&quot;[100, 200, 300, 400]&quot;</span>
        <span class="token operator">:</span>page<span class="token operator">-</span>size<span class="token operator">=</span><span class="token string">&quot;100&quot;</span>
        layout<span class="token operator">=</span><span class="token string">&quot;total, sizes, prev, pager, next, jumper&quot;</span>
        <span class="token operator">:</span>total<span class="token operator">=</span><span class="token string">&quot;400&quot;</span><span class="token operator">&gt;</span>
      <span class="token operator">&lt;</span><span class="token operator">/</span>el<span class="token operator">-</span>pagination<span class="token operator">&gt;</span>
    <span class="token operator">&lt;</span><span class="token operator">/</span>el<span class="token operator">-</span>config<span class="token operator">-</span>provider<span class="token operator">&gt;</span>
<span class="token operator">&lt;</span><span class="token operator">/</span>template<span class="token operator">&gt;</span>

<span class="token operator">&lt;</span>script lang<span class="token operator">=</span><span class="token string">'ts'</span><span class="token operator">&gt;</span>
<span class="token keyword">import</span> <span class="token punctuation">{</span> reactive<span class="token punctuation">,</span> ref<span class="token punctuation">,</span> toRefs <span class="token punctuation">}</span> <span class="token keyword">from</span> <span class="token string">'vue'</span><span class="token punctuation">;</span>
<span class="token comment">//引入vue方法</span>
<span class="token keyword">import</span> <span class="token punctuation">{</span> ElConfigProvider <span class="token punctuation">}</span> <span class="token keyword">from</span> <span class="token string">'element-plus'</span>
<span class="token comment">//中文包</span>
<span class="token keyword">import</span> zhCn <span class="token keyword">from</span> <span class="token string">&quot;element-plus/lib/locale/lang/zh-cn&quot;</span>

<span class="token keyword">export</span> <span class="token keyword">default</span><span class="token punctuation">(</span><span class="token punctuation">{</span>
    props<span class="token operator">:</span><span class="token punctuation">{</span>
      pagReviewLength<span class="token operator">:</span>Number
    <span class="token punctuation">}</span><span class="token punctuation">,</span>
    components<span class="token operator">:</span> <span class="token punctuation">{</span>
      <span class="token punctuation">[</span>ElConfigProvider<span class="token punctuation">.</span>name<span class="token punctuation">]</span><span class="token operator">:</span> ElConfigProvider
    <span class="token punctuation">}</span><span class="token punctuation">,</span>
    <span class="token function">setup</span><span class="token punctuation">(</span><span class="token parameter">props<span class="token operator">:</span>any<span class="token punctuation">,</span><span class="token punctuation">{</span>emit<span class="token punctuation">}</span><span class="token operator">:</span>any</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
      <span class="token keyword">let</span> locale <span class="token operator">=</span> zhCn
      <span class="token keyword">const</span> state <span class="token operator">=</span> <span class="token function">reactive</span><span class="token punctuation">(</span><span class="token punctuation">{</span>
        pageSize<span class="token operator">:</span><span class="token number">10</span><span class="token punctuation">,</span>
        total<span class="token operator">:</span><span class="token string">''</span><span class="token punctuation">,</span>
        currentPage1<span class="token operator">:</span><span class="token number">1</span>
      <span class="token punctuation">}</span><span class="token punctuation">)</span>
  

      <span class="token keyword">return</span> <span class="token punctuation">{</span>
        locale<span class="token punctuation">,</span>
      <span class="token punctuation">}</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span><span class="token punctuation">,</span>
<span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token operator">&lt;</span><span class="token operator">/</span>script<span class="token operator">&gt;</span>

<span class="token operator">&lt;</span>style scoped<span class="token operator">&gt;</span>

<span class="token operator">&lt;</span><span class="token operator">/</span>style<span class="token operator">&gt;</span>
</code></pre></div><p>把html中的el-pagination组件用 包裹一下，应该能解决，亲测有效！</p></div> <footer class="page-edit"><!----> <!----></footer> <div class="page-nav"><p class="inner"><span class="prev">
      ←
      <a href="/vue3/2021-08-20-1.html" class="prev">
        安装vue3
      </a></span> <span class="next"><a href="/ts/">
        ts
      </a>
      →
    </span></p></div> </main></div><div class="global-ui"></div></div>
    <script src="/assets/js/app.27eb3a33.js" defer></script><script src="/assets/js/2.377be75f.js" defer></script><script src="/assets/js/11.e95a61b2.js" defer></script>
  </body>
</html>
